#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"
void STInit(ST* ps)
{
	assert(ps);
	ps->pa = (STDataType*)malloc(sizeof(STDataType) * 4);
	if (ps->pa == NULL)
	{
		perror("STInit::mallocc");
		return;
	}
	ps->top = 0;
	ps->capacity = 4;
}
void STDestroy(ST* ps)
{
	assert(ps);
	free(ps->pa);
	ps->pa = NULL;
	ps->capacity = 0;
	ps->top = 0;
}
void STPush(ST* ps, STDataType x)
{
	assert(ps);
	if (ps->capacity == ps->top)
	{
		STDataType* tmp = (STDataType*)realloc(ps->pa, sizeof(STDataType) * ps->capacity * 2);
		if (tmp == NULL)
		{
			perror("STPush::realloc");
			return;
		}
		ps->pa = tmp;
		ps->capacity *= 2;
	}
	ps->pa[ps->top] = x;
	ps->top++;
}
void STPop(ST* ps)
{
	assert(ps);
	assert(!STEmpty(ps));
	ps->top--;
}
int STSize(ST* ps)
{
	assert(ps);
	return ps->top;
}
bool STEmpty(ST* ps)
{
	assert(ps);
	return ps->top == 0;
}
STDataType STTop(ST* ps)
{
	assert(ps);
	assert(!STEmpty(ps));
	return ps->pa[ps->top - 1];
}